#include "gtest/gtest.h"
#include "../BaseUtil/MyTest.h"
#include "PANEImp.h"
namespace PANEImp {

class PANERadioElementTest : public testing::Test {
protected:
    virtual void SetUp() {
    	doc = new PANEDocument();

    	btn1 = doc->createPANEButtonElement();
    	btn1->setNormalImage( "data/btn/left0.png" );
    	btn1->setMouseDownImage( "data/btn/left1.png" );
    	btn1->setMouseOverImage( "data/btn/left2.png" );

    	btn2 = doc->createPANEButtonElement();
    	btn2->setNormalImage( "data/btn/play0.png" );
    	btn2->setMouseDownImage( "data/btn/play1.png" );
    	btn2->setMouseOverImage( "data/btn/play2.png" );

    	radio = doc->createPANERadioElement();
    	radio->appendChild( btn1 );
    	radio->appendChild( btn2 );
    }
    virtual void TearDown() {
    	delete doc;
    }

    PANEDocument * doc;
    PANERadioElement *radio;
    PANEButtonElement *btn1, *btn2;
};

TEST_F(PANERadioElementTest, MouseOver) {
	MouseEventImp * evt1 = dynamic_cast< MouseEventImp * >( btn1->createEvent(MouseEventImp::EVENT_MOUSE_OVER) );
	ASSERT_FALSE( evt1->isStopPropagation() );
	radio->dispatchEvent( evt1 );
	ASSERT_FALSE( evt1->isStopPropagation() );
	btn1->dispatchEvent( evt1 );
	ASSERT_EQ( VisualButtonForPANE::ButtonMouseOverState, btn1->getButtonState() );

	MouseEventImp * evt2a = dynamic_cast< MouseEventImp * >( btn1->createEvent(MouseEventImp::EVENT_MOUSE_DOWN) );
	radio->setSelectedElement( 0 );
	btn1->dispatchEvent( evt2a );

	MouseEventImp * evt2b = dynamic_cast< MouseEventImp * >( btn1->createEvent(MouseEventImp::EVENT_MOUSE_OVER) );
	radio->dispatchEvent( evt2b );
	ASSERT_TRUE( evt2b->isStopPropagation() );
	ASSERT_EQ( VisualButtonForPANE::ButtonMouseDownState, btn1->getButtonState() );

	MouseEventImp * evt3 = dynamic_cast< MouseEventImp * >( btn2->createEvent(MouseEventImp::EVENT_MOUSE_OVER) );
	ASSERT_FALSE( evt3->isStopPropagation() );
	radio->dispatchEvent( evt3 );
	ASSERT_FALSE( evt3->isStopPropagation() );
	btn2->dispatchEvent( evt3 );
	ASSERT_EQ( VisualButtonForPANE::ButtonMouseDownState, btn1->getButtonState() );
	ASSERT_EQ( VisualButtonForPANE::ButtonMouseOverState, btn2->getButtonState() );
}

TEST_F(PANERadioElementTest, MouseDown) {
	MouseEventImp * evt2 = dynamic_cast< MouseEventImp * >( btn2->createEvent(MouseEventImp::EVENT_MOUSE_DOWN) );
	radio->dispatchEvent( evt2 );
	ASSERT_EQ( 1ul, radio->getSelectedElement() );

	MouseEventImp * evt1 = dynamic_cast< MouseEventImp * >( btn1->createEvent(MouseEventImp::EVENT_MOUSE_DOWN) );
	radio->dispatchEvent( evt1 );
	ASSERT_EQ( 0ul, radio->getSelectedElement() );
}

}
